<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Inference Processor | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'inference-processor.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/inference-processor.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/inference-processor.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/inference-processor.html" rel="nofollow" target="_blank">../en/inference-processor.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="ingest.html">Ingest node</a></span>
»
<span class="breadcrumb-link"><a href="ingest-processors.html">Processors</a></span>
»
<span class="breadcrumb-node">Inference Processor</span>
</div>
<div class="navheader">
<span class="prev">
<a href="htmlstrip-processor.html">« HTML Strip Processor</a>
</span>
<span class="next">
<a href="join-processor.html">Join Processor »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="inference-processor"></a>Inference Processor<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/inference.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<p>This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.</p>
</div>
</div>
<p>Uses a pre-trained data frame analytics model to infer against the data that is being
ingested in the pipeline.</p>
<div class="table">
<a id="inference-options"></a>
<p class="title"><strong>Table 52. Inference Options</strong></p>
<div class="table-contents">
<table border="1" cellpadding="4px" summary="Inference Options">
<colgroup>
<col class="col_1">
<col class="col_2">
<col class="col_3">
<col class="col_4">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Name</th>
<th align="left" valign="top">Required</th>
<th align="left" valign="top">Default</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">model_id</code></p></td>
<td align="left" valign="top"><p>yes</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>(String) The ID of the model to load and infer against.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">target_field</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p><code class="literal">ml.inference.&lt;processor_tag&gt;</code></p></td>
<td align="left" valign="top"><p>(String) Field added to incoming documents to contain results objects.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">field_map</code></p></td>
<td align="left" valign="top"><p>yes</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>(Object) Maps the document field names to the known field names of the model. This mapping takes precedence over any default mappings provided in the model configuration.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">inference_config</code></p></td>
<td align="left" valign="top"><p>yes</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>(Object) Contains the inference type and its options. There are two types: <a class="xref" href="inference-processor.html#inference-processor-regression-opt" title="Regression configuration options"><code class="literal">regression</code></a> and <a class="xref" href="inference-processor.html#inference-processor-classification-opt" title="Classification configuration options"><code class="literal">classification</code></a>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">if</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>Conditionally execute this processor.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">on_failure</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>Handle failures for this processor. See <a class="xref" href="handling-failure-in-pipelines.html" title="Handling Failures in Pipelines"><em>Handling Failures in Pipelines</em></a>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ignore_failure</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p><code class="literal">false</code></p></td>
<td align="left" valign="top"><p>Ignore failures for this processor. See <a class="xref" href="handling-failure-in-pipelines.html" title="Handling Failures in Pipelines"><em>Handling Failures in Pipelines</em></a>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">tag</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>An identifier for this processor. Useful for debugging and metrics.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "inference": {
    "model_id": "flight_delay_regression-1571767128603",
    "target_field": "FlightDelayMin_prediction_infer",
    "field_map": {},
    "inference_config": { "regression": {} }
  }
}</pre>
</div>
<h4>
<a id="inference-processor-regression-opt"></a>Regression configuration options<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/inference.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">results_field</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Specifies the field to which the inference prediction is written. Defaults to
<code class="literal">predicted_value</code>.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">num_top_feature_importance_values</code>
</span>
</dt>
<dd>
(Optional, integer)
Specifies the maximum number of
<a href="https://www.elastic.co/guide/en/machine-learning/7.7/ml-feature-importance.html" class="ulink" target="_top">feature importance</a> values per document. By
default, it is zero and no feature importance calculation occurs.
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<h4>
<a id="inference-processor-classification-opt"></a>Classification configuration options<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/inference.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">results_field</code>
</span>
</dt>
<dd>
(Optional, string)
The field that is added to incoming documents to contain the inference
prediction. Defaults to <code class="literal">predicted_value</code>.
</dd>
<dt>
<span class="term">
<code class="literal">num_top_classes</code>
</span>
</dt>
<dd>
(Optional, integer)
Specifies the number of top class predictions to return. Defaults to 0.
</dd>
<dt>
<span class="term">
<code class="literal">top_classes_results_field</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Specifies the field to which the top classes are written. Defaults to
<code class="literal">top_classes</code>.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">num_top_feature_importance_values</code>
</span>
</dt>
<dd>
(Optional, integer)
Specifies the maximum number of
<a href="https://www.elastic.co/guide/en/machine-learning/7.7/ml-feature-importance.html" class="ulink" target="_top">feature importance</a> values per document. By
default, it is zero and no feature importance calculation occurs.
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<h4>
<a id="inference-processor-config-example"></a><code class="literal">inference_config</code> examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/inference.asciidoc">edit</a>
</h4>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "inference_config": {
    "regression": {
      "results_field": "my_regression"
    }
  }
}</pre>
</div>
<p>This configuration specifies a <code class="literal">regression</code> inference and the results are
written to the <code class="literal">my_regression</code> field contained in the <code class="literal">target_field</code> results
object.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "inference_config": {
    "classification": {
      "num_top_classes": 2,
      "results_field": "prediction",
      "top_classes_results_field": "probabilities"
    }
  }
}</pre>
</div>
<p>This configuration specifies a <code class="literal">classification</code> inference. The number of
categories for which the predicted probabilities are reported is 2
(<code class="literal">num_top_classes</code>). The result is written to the <code class="literal">prediction</code> field and the top
classes to the <code class="literal">probabilities</code> field. Both fields are contained in the
<code class="literal">target_field</code> results object.</p>
<h4>
<a id="inference-processor-feature-importance"></a>Feature importance object mapping<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/inference.asciidoc">edit</a>
</h4>
<p>Update your index mapping of the feature importance result field as you can see below to
get the full benefit of aggregating and searching for
<a href="https://www.elastic.co/guide/en/machine-learning/7.7/ml-feature-importance.html" class="ulink" target="_top">feature importance</a>.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"ml.inference.feature_importance": {
  "type": "nested",
  "dynamic": true,
  "properties": {
    "feature_name": {
      "type": "keyword"
    },
    "importance": {
      "type": "double"
    }
  }
}</pre>
</div>
<p>The mapping field name for feature importance is compounded as follows:</p>
<p><code class="literal">&lt;ml.inference.target_field&gt;</code>.<code class="literal">&lt;inference.tag&gt;</code>.<code class="literal">feature_importance</code></p>
<p>If <code class="literal">inference.tag</code> is not provided in the processor definition, it is not part
of the field path. The <code class="literal">&lt;ml.inference.target_field&gt;</code> defaults to <code class="literal">ml.inference</code>.</p>
<p>For example, you provide a tag <code class="literal">foo</code> in the definition as you can see below:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "tag": "foo",
  ...
}</pre>
</div>
<p>The feature importance value is written to the <code class="literal">ml.inference.foo.feature_importance</code>
field.</p>
<p>You can also specify a target field as follows:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "tag": "foo",
  "target_field": "my_field"
}</pre>
</div>
<p>In this case, feature importance is exposed in the
<code class="literal">my_field.foo.feature_importance</code> field.</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="htmlstrip-processor.html">« HTML Strip Processor</a>
</span>
<span class="next">
<a href="join-processor.html">Join Processor »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>